package org.eddm.rule;

import java.util.Arrays;
import java.util.List;

import javax.swing.JFrame;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.swing.handler.mxKeyboardHandler;
import com.mxgraph.swing.handler.mxRubberband;
import com.mxgraph.util.mxEvent;
import com.mxgraph.util.mxEventObject;
import com.mxgraph.util.mxUtils;
import com.mxgraph.util.mxEventSource.mxIEventListener;
import com.mxgraph.view.mxGraph;
import com.mxgraph.view.mxMultiplicity;



public class Validation
{


	public Validation( mxGraph graph, mxGraphComponent graphComponent)
	{
		mxMultiplicity[] multiplicities = setMultiplicities(graph);
		
		graph.setMultiplicities(multiplicities);
		
		
		// Installs automatic validation (use editor.validation = true
		// if you are using an mxEditor instance)
		final mxGraphComponent fgraphComponent = graphComponent;
		graph.getModel().addListener(mxEvent.CHANGE, new mxIEventListener()
		{
			public void invoke(Object sender, mxEventObject evt)
			{
				fgraphComponent.validateGraph();
			}
		});
		fgraphComponent.validateGraph();
	}
	
	public void  checkValidElements( List<String> ltCellName )
	{
		
	}
	
	
	private mxMultiplicity[] setMultiplicities( mxGraph graph )
	{
		mxMultiplicity[] multiplicities = new mxMultiplicity[3];

		// Source nodes needs 1..2 connected Targets
		multiplicities[0] = new mxMultiplicity(true, "Source", null, null, 1,
				"2", Arrays.asList(new String[] { "Target" }),
				"Source Must Have 1 or 2 Targets",
				"Source Must Connect to Target", true);

		// Source node does not want any incoming connections
		multiplicities[1] = new mxMultiplicity(false, "Source", null, null, 0,
				"0", null, "Source Must Have No Incoming Edge", null, true); // Type does not matter

		// Target needs exactly one incoming connection from Source
		multiplicities[2] = new mxMultiplicity(false, "Target", null, null, 1,
				"1", Arrays.asList(new String[] { "Source" }),
				"Target Must Have 1 Source", "Target Must Connect From Source",
				true);
		
		return multiplicities;
		
	}


}
